<%
# rating takes in a recipe id
# show current rating
#     select all ratings for a recipe id, average them into a rating
#
# if a user has not rated the recipe show rating form
#
%>
<div style="border:1px solid black">
<% @current_rating = Rating.average(:rating, :conditions => ['recipe_id = ?', rating[:id]]) %>
<p>
<% if @current_rating == nil %>
  No User Rating
<% else %>
  User Rating:
  <%= @current_rating.to_s %>
  /10
<% end %>
</p>

<%# Get current users rating %>
<% @current_users_rating = Rating.find_by_recipe_id_and_user_id(rating[:id], session[:user_id]) %>
<p>
<% if @current_users_rating == nil %>
  <b>Rate this recipe:</b>
  <% @new_rating = Rating.new(:rating => nil, :recipe_id =>  rating[:id], :user_id => session[:user_id]) %>
  <%= render(:partial => "ratings/new_rating", :object => @new_rating) %>
<% else %>
 You rated this recipe a
 <%= @current_users_rating.rating.to_s %>
<% end %>
</p>
</div>